package com.example.es.myapplication;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.es.myapplication.BaseFragment;
import com.example.zqm.neu612.Adapter.CollectAdapter;
import com.example.zqm.neu612.JavaBean.CollectionBean;
import com.example.zqm.neu612.Model.UserModel;
import com.example.zqm.neu612.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * A simple {@link Fragment} subclass.
 */
public class CollectShopFragment extends BaseFragment {

  RecyclerView collect_rv;
    private View view = null;

    public CollectShopFragment(){
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
        view = inflater.inflate(R.layout.fragment_container,container,false);

        initViews();
        return view;
    }
    @Override
    public void onResume() {
        super.onResume();
        initData();
    }
    public void initViews(){
        collect_rv = (RecyclerView)view.findViewById(R.id.collect_rv);
        collect_rv.setLayoutManager(new LinearLayoutManager(getActivity()));
    }
    public void initData(){
        UserModel userModel = new UserModel();
        Call call = userModel.getAllUserCollection(getUser_id(),"0");
        Callback<List<CollectionBean>> callback = new Callback<List<CollectionBean>>() {
            @Override
            public void onResponse(Call<List<CollectionBean>> call, Response<List<CollectionBean>> response) {
                List<CollectionBean> collectionBeen = response.body();
                collect_rv.setAdapter(new CollectAdapter(context,collectionBeen));
            }

            @Override
            public void onFailure(Call<List<CollectionBean>> call, Throwable t) {
                System.out.println("请求失败！");
                Log.i("onFailure","onFailure="+t.getMessage());
            }
        };
        call.enqueue(callback);
    }




}
